home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / funadd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1.3 KB  |  62 lines

  1. /*
  2. \funcref{fun\_add}{void fun\_add ()}
  3.     {}
  4.     {}
  5.     {pop(), xstrdup(), copylist(), addtolist(), discard()}
  6.     {}
  7.     {funadd.c}
  8.     {
  9.  
  10.         Function {\em fun\_add()} processes opcode {\em op\_add}. Two variables
  11.         are popped and added. Depending on their type, two integer values are
  12.         added, two strings are concatenated, or two lists are merged.
  13.  
  14.         The result of the addition is stored in a temporary variable, which is
  15.         then pushed.
  16.  
  17.         The two popped variables are discarded after use.
  18.  
  19.     }
  20. */
  21.  
  22. #include "icm-exec.h"
  23.  
  24. void fun_add ()
  25. {
  26.     VAR_
  27.         tmp,
  28.         lval,
  29.         rval;
  30.     register unsigned
  31.         i;
  32.     register LIST_
  33.         *rlist;
  34.  
  35.     rval = pop ();
  36.     lval = pop ();
  37.  
  38.     if (lval.type & e_str)
  39.     {
  40.         tmp = newvar (e_str);
  41.         tmp.vu.i->ls.str =
  42.             xstrcat (xstrdup (lval.vu.i->ls.str), rval.vu.i->ls.str);
  43.     }
  44.     else if (lval.type & e_int)
  45.     {
  46.         tmp.type = e_int;
  47.         tmp.vu.intval = lval.vu.intval + rval.vu.intval;
  48.     }
  49.     else
  50.     {
  51.         tmp = copylist (lval);
  52.         rlist = &(rval.vu.i->ls.list);
  53.         for (i = 0; i < rlist->size; i++)
  54.             if (! inlist (tmp, rlist->element [i]) )
  55.                 tmp = addtolist (tmp, rlist->element [i]);
  56.     }
  57.  
  58.     push (tmp);
  59.     discard (lval);
  60.     discard (rval);
  61. }
  62.